

import java.util.Vector;

import meta.symbolsAndTime.SAUNA.Map;
import meta.symbolsAndTime.SAUNA.SpatialProximityVarOH;
import meta.symbolsAndTime.SAUNA.TemporalPolyhedronScheduler;
import multi.SAUNA.Path;
import multi.SAUNA.TemporalPolyhedronNetworkSolver;
import org.metacsp.multi.spatial.rectangleAlgebra.Point;
import org.metacsp.framework.ValueOrderingH;
import org.metacsp.framework.VariableOrderingH;

public class TestTemporalPolyhedronSchedulerAtlasCopco {

	public static void main(String[] args) {
		
		//vehicle geometry
		double dimX = 1, dimY = 0.5;

		//Scheduler
		TemporalPolyhedronScheduler metaSolver = new TemporalPolyhedronScheduler(0,200000,0);
		//this is the temporal solver underneath the scheduler
		TemporalPolyhedronNetworkSolver groundSolver = (TemporalPolyhedronNetworkSolver)metaSolver.getConstraintSolvers()[0];
		
		//Most critical conflict is the earliest one
		//VariableOrderingH varOH = new EarliestStartTimeVarOH();
		//VariableOrderingH varOH = new LatestStartTimeVarOH();
		VariableOrderingH varOH = new SpatialProximityVarOH();
		
		//Do nothing, as this is already done in the Map metaConstraint.
		ValueOrderingH valOH = null;
		
		//Load the map from file and use it as a domain feature for the scheduler
		Map map = new Map("SAUNA/sauna.map", varOH, valOH);
		metaSolver.addMetaConstraint(map);
		
		Vector<Path> paths = new Vector<Path>();
		paths.add(new Path("Vehicle A", "SAUNA/benchmarks/tampraLogSubMap1Path1", new Point(0,0), map, 0.01, 5));
		paths.add(new Path("Vehicle B", "SAUNA/benchmarks/tampraLogSubMap1Path2", new Point(0,0), map, 0.01, 5));
		paths.add(new Path("Vehicle C", "SAUNA/benchmarks/tampraLogSubMap1Path3", new Point(0,0), map, 0.01, 5));
		paths.add(new Path("Vehicle D", "SAUNA/benchmarks/tampraLogSubMap2Path1", new Point(0,0), map, 0.01, 5));
		paths.add(new Path("Vehicle E", "SAUNA/benchmarks/tampraLogSubMap2Path2", new Point(0,0), map, 0.01, 5));
		paths.add(new Path("Vehicle F", "SAUNA/benchmarks/tampraLogSubMap2Path3New", new Point(0,0), map, 0.01, 5));
		paths.add(new Path("Vehicle G", "SAUNA/benchmarks/tampraFullMap2", new Point(0,0), map, 0.01, 5));
		
		//Make variables
		int numberOfPolys = 0;
		for (Path p : paths) {
			if (p.createConvexPolyhedra(groundSolver, dimX, dimY, 1, 0.1, 0.7, 0.8) == null) {
				System.out.println("FAILED TO CREATE POLYS FOR " + p.getName());
				System.exit(0);
			}
			numberOfPolys += p.getConvexPolygons().length;
		}
		System.out.println("Number of polygons: " + numberOfPolys);
		
		//ConstraintNetwork.draw(groundSolver.getConstraintNetwork());
		
		//System.out.println(Arrays.toString(map.getMetaVariables()));
		//System.out.println("SOLVED? " + metaSolver.backtrack());
		//metaSolver.draw();
		
		//Draw consistency feature
		map.draw(groundSolver.getConstraintNetwork());
		//map.animate();
		
//		Path onePath = paths.firstElement();
//		ConvexPolygon act = onePath.getConvexPolygons()[0];
//		//last poly meets dummy var that lasts till H
//		AllenIntervalConstraint constr = new AllenIntervalConstraint(groundSolver, AllenIntervalConstraint.Type.Release, new Bounds(5,5));
//		constr.setFrom(act);
//		constr.setTo(act);
//		long begin = Calendar.getInstance().getTimeInMillis();
//		boolean idunno = groundSolver.addConstraint(constr);
//		long end = Calendar.getInstance().getTimeInMillis();
//		System.out.println("Added constraint? " + idunno + "(" + (end-begin) + ")");
//		

		

	}
}

